﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class DocumentService : IDocumentService
    {
        private IDocumentRepository _documentRepository;

        #region IDocumentService Members
        
        /// <summary>
        /// create new document
        /// </summary>
        /// <param name="theNewDocument">the new document instance</param>
        /// <returns>the new document's ID</returns>
        public int CreateNewDocument(Data.Entity.Document theNewDocument)
        {
            if (theNewDocument == null)
            {
                return 0;
            }

            if (_documentRepository == null)
            {
                _documentRepository = new DocumentRepository();
            }

            return _documentRepository.CreateNewDocument(theNewDocument);
        }

        public int DeleteDocument(int id)
        {
            if (id <= 0)
            {
                return 0;
            }

            if (_documentRepository == null)
            {
                _documentRepository = new DocumentRepository();
            }

            return _documentRepository.DeleteDocument(id);
        }

        public int DeleteProductDocumentMapping(int documentID)
        {
            if (documentID <= 0)
            {
                return 0;
            }

            if (_documentRepository == null)
            {
                _documentRepository = new DocumentRepository();
            }

            return _documentRepository.DeleteProductDocumentMapping(documentID);
        }

        public IList<Data.Entity.Document> GetDocumentByProduct(int productID)
        {
            if (productID <= 0)
            {
                return null;
            }

            if (_documentRepository == null)
            {
                _documentRepository = new DocumentRepository();
            }

            return _documentRepository.GetDocumentByProduct(productID);
        }

        #endregion
    }

}
